package com.paradogs.framework.server;

import com.baidu.bjf.remoting.protobuf.FieldType;
import com.baidu.bjf.remoting.protobuf.annotation.Protobuf;
import com.baidu.bjf.remoting.protobuf.annotation.ProtobufClass;
import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.IOException;

/**
 * @author: yumi
 * @date: 2023/12/27  16:05
 * @Description: TODO
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ProtobufClass
public class ByteMessage implements IMessageSerializable {

//    @Protobuf(fieldType = FieldType.OBJECT, order = 1)
    private MessageHeader header;

//    @Protobuf(fieldType = FieldType.BYTES, order = 2)
    private byte[] dataBytes;


    @Override
    public void serialization(ByteBuf out) {
        out.writeBytes(this.dataBytes);
    }

    @Override
    public void deserialization(ByteBuf in) {
        this.dataBytes =  new byte[in.readableBytes()];
        in.readBytes(this.dataBytes);
    }

    @Override
    public void deserialization(byte[] bytes) {
        this.dataBytes = bytes;
    }

}
